package com.c.yinyuezhushou.MyTool;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

public class Immersed {
    public static void setImmersed(View view, Activity activity,int co){

        Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            if (co == 0){
                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            }else{
                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            }
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

            ViewGroup.LayoutParams params = view.getLayoutParams();

            int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
            int topMargin = activity.getResources().getDimensionPixelSize(resourceId);

            params.height = params.height + topMargin;
            view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + topMargin, view.getPaddingRight(), view.getPaddingBottom());
            view.setLayoutParams(params);
        }

    }
}
